﻿<%@ Page Title="Stock Types" Language="C#" MasterPageFile="~/Backoffice/BackOffice.Master"
    AutoEventWireup="true" CodeBehind="StockTypes.aspx.cs" Inherits="TreaShares.Backoffice.User.StockTypes" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadGrid ID="RadGrid2" GridLines="None" runat="server" AllowAutomaticDeletes="True"
        AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
        AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ShowStatusBar="True"
        CellSpacing="0" >
        <%--<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" DataSourceID="LinqDataSource1"
        GridLines="None" AllowAutomaticUpdates="True">--%>
        <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
            <Excel Format="ExcelML" />
        </ExportSettings>
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowMultiColumnSorting="True"
            DataKeyNames="Id" AllowSorting="True" CommandItemDisplay="TopAndBottom">
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="Name" DefaultInsertValue="" HeaderText="Name"
                    SortExpression="Name" UniqueName="Name">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    <ItemStyle CssClass="MyImageButton" />
                </telerik:GridEditCommandColumn>
                <telerik:GridTemplateColumn>
                    <ItemTemplate>
                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Icons/trash.gif"
                            CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete?')" Enabled=<%# Check(Eval("Cnt")) %> />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <%--<telerik:GridButtonColumn UniqueName="DeleteColumn" CommandName="Delete" ButtonType="ImageButton" ImageUrl="~/Images/Icons/trash.gif" ConfirmText="Are you sure you want to delete?" />--%>
            </Columns>
            <CommandItemSettings ShowExportToCsvButton="true" />
            <EditFormSettings ColumnNumber="2" InsertCaption="New Stock type" EditFormType="AutoGenerated">
                <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                    UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                </EditColumn>
                <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString %>"
        SelectCommand="select st.Id,st.Name,COUNT(s.Id) as cnt from StockTypes st left join Stocks s on st.Id = s.StockType WHERE (st.ClientId = @ClientId) group by st.Id, st.Name"
        UpdateCommand="UPDATE StockTypes SET Name = @Name WHERE (Id = @Id)" InsertCommand="INSERT INTO StockTypes (ClientId, Name) VALUES (@ClientId, @Name)"
        DeleteCommand="DELETE FROM StockTypes WHERE (Id = @Id)">
        <DeleteParameters>
            <asp:Parameter Name="Id" />
        </DeleteParameters>
        <InsertParameters>
            <asp:CookieParameter CookieName="OrganisationId" Name="ClientId" DbType="Guid" />
            <asp:Parameter Name="Name" />
        </InsertParameters>
        <SelectParameters>
            <asp:CookieParameter CookieName="OrganisationId" Name="ClientId" DbType="Guid" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Id" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="200px" />
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="TreaShares.Backoffice.DataLayer.TreasharesDataContext"
        EntityTypeName="" Select="new (Id, Name)" TableName="StockTypes" Where="ClientId == @ClientId"
        EnableUpdate="true" OrderBy="Name">
        <WhereParameters>
            <asp:CookieParameter CookieName="OrganisationId" DbType="Guid" Name="ClientId" />
        </WhereParameters>
        <UpdateParameters>
            <asp:ControlParameter ControlID="GridTextBoxColumnEditor1" Name="Name" PropertyName="Text"
                Type="String" />
        </UpdateParameters>
    </asp:LinqDataSource>
</asp:Content>
